﻿using System.Collections.Generic;
using System.Text;

namespace lwzlz.Application.Model
{
    public class DataTableBll
    {
        private static DataTableBll _instance;

        public static DataTableBll GetInstance()
        {
            return _instance ?? (_instance = new DataTableBll());
        }
        /// <summary>
        /// 获取数据
        /// </summary>
        /// <param name="db">数据库名称</param>
        /// <returns></returns>
        public IList<DataTableInfo> GetList(string db)
        {
            return DataTableDal.GetInstance().GetList(db, "");
        }

        //layui
        public string GetMenu(string db, string searchTable)
        {
            var builder = new StringBuilder();
            string strTwo = GetTwoMenu(db, searchTable);
            if (!string.IsNullOrEmpty(strTwo))
            {
                builder.AppendLine(strTwo);
            }

            return builder.ToString();
        }
        //layui
        private string GetTwoMenu(string db, string searchTable)
        {
            var builder = new StringBuilder();
            var twoList = DataTableDal.GetInstance().GetList(db, searchTable);
            if (twoList.Count > 0)
            {
                var strTwoMenu = new StringBuilder();
                foreach (var twoMenu in twoList)
                {
                    //加密要传入的数据库连接字符串
                    strTwoMenu.AppendFormat("<dd style=\"height:60px;line-height:60px;\" onclick=\"refresh(\'{0}\')\">" +
                        "<span style=\"margin-left:5px;font-size:16px;\">{1}</span>" +
                        "<span style=\"margin-left:18px;font-size:16px;\" id=\"{2}\">({3})</span></dd>",
                                            twoMenu.Name, twoMenu.Name, twoMenu.Name, twoMenu.Description);
                }
                if (!string.IsNullOrEmpty(strTwoMenu.ToString()))
                {
                    builder.AppendLine(strTwoMenu.ToString());
                }
            }
            return builder.ToString();
        }
    }
}